#!/usr/bin/python
# -*- coding: UTF-8 -*-
from updateuser import user_info
from business.User.UserCompetation import UserCompetation
import time

import pytest
import json

from business.login import Login
from pom.base import BaseDriver

from selenium import webdriver
from common.api_corrent_answer import api_answer

com_id = "619dd1658a190ab3d516505c"
# user_info(com_id, "personal")

def getData():
    with open(r'D:\pythoncode\trainning\common\user.json', 'r+') as user:
        data = json.load(user)
        ret_data = ()
        name = []
        passwd = []
        for i in range(1, len(data) + 1):
            print(data['{}'.format(i)]['name'])
            name.append(data['{}'.format(i)]['name'])
            passwd.append(data['{}'.format(i)]['passwd'])
            ret_data = zip(name, passwd)
        return ret_data

class TestUser():

    def setup_class(self):
        self.dir = api_answer().api_answer(com_id)


    def setup_method(self):
        self.driver = webdriver.Chrome()
        BaseDriver(self.driver).get_url()
        self.l = Login(self.driver)
        self.u = UserCompetation(self.driver)

    def tearDown_method(self):
        BaseDriver(self.driver).quit_webdriver()



    @pytest.mark.parametrize('name,passwd', getData())
    def test_answer(self, name, passwd):
        BaseDriver.logger.info(name + "开始答题")
        self.l.system_login(name, passwd)
        score = api_answer().set_answer(self.dir, 15, name)
        total_score = score[1]
        score = score[0]
        # total_score = api_answer().set_answer(self.__class__.dir[0], 10, name)[1]
        answer_file = self.dir + '/{}.csv'.format(name)
        print(score, total_score)
        print(round(int(score) / int(total_score), 4))
        # api_answer().set_answer(r'D:\pythoncode\trainning\common\anser_csv\测试大屏详细状态', 43, name)
        #
        # answer_file =  r'D:\pythoncode\trainning\common\anser_csv\1616'+ '\{}.csv'.format('j10')
        self.u.answer(answer_file, 26)
        time.sleep(5)


if __name__ == '__main__':
    pytest.main()